package PlaneGame.CODE;

import java.awt.*;
import java.util.Vector;

public abstract class EnemyGenerator extends Generator{
    int maxRate =500;
    int gapTime=10000;
    Vector<Enemy> tVector =new Vector<>();
    @Override
    void init() {
        super.init();
        createRate=3000;
        if(tVector!=null){
            for (int i = 0; i < tVector.size(); i++) {
                tVector.elementAt(i).off();
            }
        }
    }
    @Override
    void change() {
        super.change();
        harder();
    }
    void harder() {
        if (createRate> maxRate) {
            createRate-=100;
        }else {
            close();
            try {
                Thread.sleep(gapTime);//切换下一波敌机
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            open();
        }
    }
    void close(){
        this.off();
    }
    abstract void open();
    void create(){
        tVector.add(new Enemy());
        tVector.lastElement().shift();
        new Thread(tVector.lastElement()).start();
    }
    void delete(){
        for (int i = 0; i < tVector.size(); i++) {
            if(!tVector.elementAt(i).on_off){
                tVector.removeElementAt(i);
            }
        }
    }
    void drawVector(Graphics g){
        for (int i = 0; i < tVector.size(); i++) {
            tVector.elementAt(i).drawMyself(g);
        }
    }
}
